<template>
  <div style="height:100%;width:100%;position:relative;">
      <div class="pagetop" ref="buttondiv">
          <template>
              <table width="100%">
                  <tr>
                      <td align="right" width="60px">质控日期</td>
                      <td width="280px">
                          <el-date-picker v-model="qcdate[0]" type="date" placeholder="开始日期" value-format="yyyy-MM-dd" style="width:130px">
                          </el-date-picker> 至
                          <el-date-picker v-model="qcdate[1]" type="date" placeholder="结束日期" value-format="yyyy-MM-dd" style="width:130px">
                          </el-date-picker>
                          <!-- <el-date-picker v-model="qcdate" type="daterange" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" style="width:240px"></el-date-picker> -->
                      </td>
                      <td align="right" width="60px">批号</td>
                      <td width="220px">
                          <el-input v-model="batchno" id="batchno" style="width:100%"></el-input>
                      </td>
                      <td align="right" width="60px">水平</td>
                      <td width="80px">
                          <rm-ddl-common datatype="seccode" kindno="QCLEVEL" dataname="水平" v-model="qclevel" width="120px" @change="qclevelChange"></rm-ddl-common>
                      </td>
                      <td align="right" width="80px">检验工作组</td>
                      <td width="120px">
                          <rm-ddl-common v-model="labgroupid" clearable filterable :appendtobody="true" visible-change:true datatype="labgroup" dataname="检验工作组" width="200px" @change="labgroupChange"></rm-ddl-common>
                      </td>
                      <td colspan="3"></td>
                  </tr>
                  <tr>
                      <td align="right" width="60px">仪器</td>
                      <td width="280px">
                          <rm-ddl-instrument @change="labinstrumentchange" width="280px" v-model="instrId" defaultflag="1" prgno="LIS522" :clearable="true"></rm-ddl-instrument>
                      </td>

                      <td align="right">质控项目</td>
                      <td width="220px">
                          <rm-ddl-common datatype="instrrptitem" dataname="仪器对应质控项目" v-model="qcitem" :instrid="parseInt(instrId)" width="220px" @change="qcitemChange"> </rm-ddl-common>
                      </td>
                      <td align="right" width="60px">处理状态</td>
                      <td width="80px">
                          <el-select v-model="outcontrolok" placeholder="请选择" style="width:100%;">
                              <el-option key="1" label="已处理" value="1"></el-option>
                              <el-option key="2" label="未处理" value="2"></el-option>
                              <el-option key="all" label="全部" value="0"></el-option>
                          </el-select>
                      </td>
                  </tr>
                  <tr>
                      <td align="right" colspan="14" style="right: 5px;">
                          <el-button type="primary" icon="el-icon-search" @click="initialList" v-has="'PINQUERY'">查询</el-button>
                          <el-button icon="el-icon-printer" @click="printrecord(1)">打印清单</el-button>
                          <el-button icon="el-icon-printer" @click="RptStyleSetting(1)">清单样式</el-button>
                          <el-button icon="el-icon-printer" @click="printrecord(2)">失控报告打印</el-button>
                          <el-button icon="el-icon-view" @click="previewData">失控报告预览</el-button>
                          <el-button icon="el-icon-printer" @click="RptStyleSetting(2)">失控报告样式</el-button>
                          <el-button @click="BtnExport" icon="el-icon-upload2">导出</el-button>
                          <!-- <el-button icon="el-icon-printer" @click="btnPrint(1)">打印清单(F10)</el-button>
                          <el-button icon="el-icon-printer" @click="btnPrint(2)">打印失控报告(F11)</el-button> -->
                          <el-button icon="el-icon-close" @click="BtnExc">退出(X)</el-button>
                      </td>
                  </tr>
              </table>
          </template>
      </div>
      <div class="pagecenter">
          <div ref="xTableDiv" style="height:99%;width:100%">
              <vxe-table class="mytable-style" show-overflow ref="xTable" height="auto" width="100%" :loading="loading" :select-config="{ reserve: true }" :data.sync="tableData1" border size="mini" :keyboard-config="keyConfig" :mouse-config="{ selected: true }" show-header-overflow highlight-current-row highlight-hover-row resizable stripe :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }" :cell-class-name="getOutcontrolClassname" @current-change="currentChangeEvent" @cell-click="CellDblClick">
                  <vxe-table-column field="seq" title="序号" width="50px" header-align="center" align="center">
                  </vxe-table-column>
                  <vxe-table-column field="labgroupname" title="工作组" width="150px" header-align="center"></vxe-table-column>
                  <vxe-table-column field="instrname" title="仪器" width="150px" header-align="center">
                  </vxe-table-column>
                  <vxe-table-column field="qcdate" title="质控日期" width="100px" align="center" :formatter="['toDateString', 'yyyy-MM-dd']">
                  </vxe-table-column>
                  <vxe-table-column field="itemcode_en" title="英文缩写" width="100" header-align="center"></vxe-table-column>
                  <vxe-table-column field="rpt_itemname" title="项目名称" width="120" header-align="center"></vxe-table-column>
                  <vxe-table-column field="batchno" title="批号" width="100" header-align="center"></vxe-table-column>
                  <vxe-table-column field="qclevel" title="水平" width="50" align="center"></vxe-table-column>
                  <vxe-table-column field="tagvalue" title="基准靶值" width="80" align="center"></vxe-table-column>
                  <vxe-table-column field="sd" title="基准SD" width="80" align="center"></vxe-table-column>
                  <vxe-table-column field="displayvalue" title="显示结果" width="80" header-align="center" align="right"></vxe-table-column>
                  <vxe-table-column field="outtransokresult" title="失控修正结果" width="100" header-align="center" align="right"></vxe-table-column>
                  <vxe-table-column field="outcontroltips" title="失控提示" width="150" header-align="center"></vxe-table-column>
                  <vxe-table-column field="outcontrolreason" title="失控原因" width="150" header-align="center"></vxe-table-column>
                  <vxe-table-column field="outcontroloperation" title="失控处理" width="150" header-align="center"></vxe-table-column>
                  <vxe-table-column field="outcontrolresult" title="处理结果" width="80" header-align="center"></vxe-table-column>
                  <vxe-table-column field="resultdt" title="结果时间" width="140" align="center" :formatter="['toDateString', 'yyyy-MM-dd  HH:mm:ss']"></vxe-table-column>
                  <vxe-table-column field="calculatevalue" title="计算结果" width="80" header-align="center" align="right"></vxe-table-column>
                  <vxe-table-column field="calculatesd" title="计算SD" width="80" header-align="center" align="right"></vxe-table-column>
                  <vxe-table-column field="controlstatus" title="在控" width="80" align="center" :formatter="['formatSelect', controlstatusList]"></vxe-table-column>
                  <vxe-table-column field="inuseflag" title="累计" width="50" align="center" :formatter="['formatSelect', dgList]"></vxe-table-column>
                  <vxe-table-column field="drawflag" title="画图" width="50" align="center" :formatter="['formatSelect', dgList]"></vxe-table-column>
                  <vxe-table-column field="checkflag" title="审核" width="50" align="center" :formatter="['formatSelect', dgList]"></vxe-table-column>
                  <vxe-table-column field="begindt" title="靶值启用日期" width="140" align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                  <vxe-table-column field="cp_outcontroluser" title="处理人" width="60" header-align="center"></vxe-table-column>
                  <vxe-table-column field="outcontroloperatedt" title="处理时间" width="140" align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                  <vxe-table-column field="checkdt" title="审核时间" width="140" align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                  <vxe-table-column field="cp_checkuser" title="审核人" width="60" header-align="center"></vxe-table-column>
                  <vxe-table-column field="lastmodifydt" title="最后修改时间" width="140" align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                  <vxe-table-column field="cp_lastmodifyuser" title="最后修改人" width="90" header-align="center"></vxe-table-column>
                  <vxe-table-column field="comments" title="备注" width="100" header-align="center"></vxe-table-column>
                  <vxe-table-column field="qcvaluesign" title="结果标识" width="150" header-align="center"></vxe-table-column>
                  <vxe-table-column field="cliniceffect" title="临床影响" width="150" header-align="center"></vxe-table-column>
                  <vxe-table-column field="premunition" title="预防措施" width="100" header-align="center"></vxe-table-column>
                  <!-- <vxe-table-column field="originalvalue" title="机器原始结果" width="100" header-align="center"></vxe-table-column> -->
                  <vxe-table-column field="qcname" title="质控品名称" width="100" header-align="center"></vxe-table-column>
                  <vxe-table-column field="expriedt" title="有效期" width="130" header-align="center"></vxe-table-column>
                  <vxe-table-column field="qcdataid" title="质控结果ID" width="100" header-align="center"></vxe-table-column>
                  <vxe-table-column field="qcitemvalueid" title="靶值标准ID" width="100" header-align="center"></vxe-table-column>
                  <vxe-table-column field="qcid" title="质控品ID" width="80" header-align="center"></vxe-table-column>
              </vxe-table>
              <div style="display:none">
                  <vxe-table :v-show="false" :data="verifyData" @current-change="infochange" height="300px" highlight-current-row highlight-hover-row resizable highlight-hover-column border show-header-overflow="tooltip" show-overflow="tooltip" header-align="center" size="mini" stripe ref="verifytable">
                      <vxe-table-column field="samplenof" title="更换前标本号" width="160px"></vxe-table-column>
                      <vxe-table-column field="barcodef" title="更换前条码号" width="160px"></vxe-table-column>
                      <vxe-table-column field="result_strf" title="更换前结果" width="160px"></vxe-table-column>
                      <vxe-table-column field="samplenob" title="更换后标本号" width="160px"></vxe-table-column>
                      <vxe-table-column field="barcodeb" title="更换后条码号" width="160px"></vxe-table-column>
                      <vxe-table-column field="result_strb" title="更换后结果" width="160px"></vxe-table-column>
                      <vxe-table-column field="bias" title="偏倚%" width="160px"></vxe-table-column>
                      <vxe-table-column field="verityrule" title="判断类型" width="160px"></vxe-table-column>
                      <vxe-table-column field="tea" title="判断标准" width="160px"></vxe-table-column>
                      <vxe-table-column field="verifyerna" title="校验人" width="160px"></vxe-table-column>
                      <vxe-table-column field="verifyflagna" title="是否合格" width="160px"></vxe-table-column>
                      <vxe-table-column field="verifyna" title="是否通过" width="160px"></vxe-table-column>
                  </vxe-table>
              </div>
              <div style="display:none">
                  <vxe-table :v-show="false" :data="signData" @current-change="infochange" height="300px" highlight-current-row highlight-hover-row resizable highlight-hover-column border show-header-overflow="tooltip" show-overflow="tooltip" header-align="center" size="mini" stripe ref="signtable">
                      <vxe-table-column v-if="false" field="checkusersign" title="审核人签名" width="160px"></vxe-table-column>
                      <vxe-table-column v-if="false" field="outcontrolusersign" title="处理人签名" width="160px"></vxe-table-column>
                  </vxe-table>
              </div>
          </div>
      </div>
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialogAdviceVisible" title="失控原因填写" :destroy-on-close="true" top="5vh" width="600px">
          <div>
              <table style="width: 100%; border-spacing: 0px; margin-top: 5px">
                  <tr>
                      <td>
                          <div>
                              <el-input type="textarea" :rows="12" v-model="advicetxt"></el-input>
                          </div>
                      </td>
                      <td>
                          <div style="margin-left: 15px">
                              <el-button style="display: block" @click="AdviceSubmit()">提 交</el-button>
                              <el-button style="display: block; margin-left: 0px; margin-top: 5px" @click="dialogAdviceVisible = false">取 消</el-button>
                              <el-checkbox v-model="appendChangeRow" style="margin-top: 20px; display: block">追加时自动换行</el-checkbox>
                              <div style="margin-top: 20px">
                                  <span style="color: blue">说明:<br />单击为追加<br />双击为替换</span>
                              </div>
                          </div>
                      </td>
                  </tr>
                  <tr>
                      <td style="width: 450px">
                          <vxe-table :data="tableDataAdvice" :loading="loadingAdvice" @cell-click="AdviceClick" @cell-dblclick="AdvicedblClick" height="300px" highlight-current-row highlight-hover-row resizable highlight-hover-column border show-header-overflow="tooltip" show-overflow="tooltip" header-align="center" size="mini" stripe width="400px">
                              <vxe-table-column field="txtinfo" title="文字描述" width="160px"></vxe-table-column>
                              <vxe-table-column field="seq" title="序号" width="80px"></vxe-table-column>
                              <vxe-table-column field="inputcode" title="输入码" width="80px"></vxe-table-column>
                          </vxe-table>
                      </td>
                      <td style="text-align: center">
                          <vxe-table :data="txtinfoarr" @current-change="infochange" height="300px" highlight-current-row highlight-hover-row resizable highlight-hover-column border show-header-overflow="tooltip" show-overflow="tooltip" header-align="center" size="mini" stripe ref="txtinfokind">
                              <vxe-table-column field="txtinfokind" title="描述归类" width="160px"></vxe-table-column>
                          </vxe-table>
                      </td>
                  </tr>
              </table>
          </div>
      </el-dialog>
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="bShowOutReport" title="失控报告预览" :destroy-on-close="true" top="5vh" width="710px">
          <div style="height:700px;width:700px;border:1px solid #CCC;" v-loading="rightloading" element-loading-text="数据加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)">
              <!--   <pdf v-for="i in pdfPages" :key="i" :src="url" :page="i"></pdf> -->
              <embed :src="htmlstr" type="application/pdf" width="100%" height="99%" :key="htmlstrkey">
          </div>
      </el-dialog>
      <!-- <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="verifyDlg" title="verifyDlg" :destroy-on-close="true" top="5vh" width="710px"> -->

      <!-- </el-dialog> -->
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils"; //引入工具类
XEUtils.mixin({
  // 自定义全局的格式化处理函数
  formatSelect(cellValue, list) {
      let item = list.find((item) => item.value == cellValue);
      return item ? item.label : "";
  },
});
export default {
  name: "LIS522",
  data() {
      return {
          loading: false,
          instrId: 0,
          labgroupid: "",
          qcdate: [],
          tableData1: [],
          qcitem: "",
          batchno: "",
          outcontrolok: "0",
          qclevel: "",
          labgroupval: "",
          //报告备注弹窗
          dialogAdviceVisible: false,
          appendChangeRow: false,
          advicetxt: "",
          tableDataAdvice: [],
          tableDataAdviceall: [],
          loadingAdvice: false,
          txtkind: "全部",
          txtinfoarr: [],
          infortype: -1,
          tempappraise: {},
          qclevelOption: [
              { label: "全部", value: 0 },
              { label: "1", value: 1 },
              { label: "2", value: 2 },
              { label: "3", value: 3 },
              { label: "4", value: 4 },
              { label: "5", value: 5 },
              { label: "6", value: 6 },
          ],
          controlstatusList: [
              { label: "失控", value: "0" },
              { label: "在控", value: "1" },
              { label: "警告", value: "3" },
              { label: "未判定", value: null },
          ],
          dgList: [
              { label: "", value: "0" },
              { label: "√", value: "1" },
          ],

          keyConfig: {
              isArrow: true,
              isDel: true,
              isTab: true,
              isEdit: true,
              editMethod: ({ seq, row, rowIndex, column, columnIndex, cell }) => {},
          },
          printSql: "",
          styleIdQCList: 0,
          styleIdOC: 0,
          nowQcdataid: 0,
          currow: {},
          infortype: -1,
          rightloading: false,
          bShowOutReport: false,
          htmlstr: "",
          htmlstrkey: 0,
          verifyDlg: false,
          verifyData: [],
          signData: [],
          instrname: "",
          qclevelname: "",
          qcitemname: "",
      };
  },

  //html加载完成之前，执行。执行顺序：父组件-子组件
  created() {
      this.qcdate = ["", ""];
      this.qcdate[0] = XEUtils.toDateString(new Date(), "yyyy-MM-dd"); //起 始结束日期
      this.qcdate[1] = XEUtils.toDateString(new Date(), "yyyy-MM-dd");

      //TODO
      //styleid=
      // this.initialList(); //初始化主列表
  },
  //.html加载完成后执行。执行顺序：子组件-父组件
  mounted() {
      this.$tool
          .request({
              url: "LIS/LIS5/LIS522",
              method: "post",
              data: {
                  action: "styleId",
              },
          })
          .then((response) => {
              // console.log(response);
              this.styleIdQCList = response.styleid1;
              this.styleIdOC = response.styleid2;
          });
  },
  updated() {},
  methods: {
      CellDblClick({ row, rowIndex, $rowIndex, column }) {
          this.currow = row;
          if (this.currow && column.property == "outcontrolreason") {
              this.ShowAdvice(row, 0);
          }
      },
      //导出
      BtnExport() {
          // this.$refs.lXTable.exportCsv({
          //     filename: "INV122 供应商维护(全局)",
          // });
          let tableColumn = this.$refs.xTable.getColumns();
          let extableColumn = [];
          tableColumn.forEach((item) => {
              extableColumn.push({ title: item.title, field: item.property });
          });
          let filtertxt = this.getExportFilter();
          this.$pub.exportTableExcel(this.tableData1, extableColumn, "LIS522 失控数据/失控报告.xlsx", filtertxt);
      },
      // 获取当前导出文件的所有查询条件
      getExportFilter() {
          let filtertxt = "";
          let qcdttxt = "";
          if (this.qcdate[0]) qcdttxt += XEUtils.toDateString(this.qcdate[0], "yyyy-MM-dd");
          if (this.qcdate[1]) qcdttxt += "至" + XEUtils.toDateString(this.qcdate[1], "yyyy-MM-dd");
          if (qcdttxt) filtertxt += "质控日期:" + qcdttxt + "; ";
          if (this.batchno) filtertxt += "批号:" + this.batchno + "; ";
          if (this.qclevel) filtertxt += "水平:" + this.qclevelname + "; ";
          if (this.labgroupid) filtertxt += "检验工作组:" + this.labgroupval + "; ";
          if (this.instrId) filtertxt += "仪器:" + this.instrname + "; ";
          if (this.qcitem) filtertxt += "质控项目:" + this.qcitemname + "; ";
          filtertxt += "处理状态:" + (this.outcontrolok == "1" ? "已处理" : this.outcontrolok == "2" ? "未处理" : "全部") + "; ";
          return filtertxt;
      },
      getOptionName(option) {
          if (option && option.length > 0) {
              let optionname = "";
              option.forEach((item) => {
                  if (item.hasOwnProperty("label")) {
                      optionname += item.label + ",";
                  } else {
                      optionname += item.display + ",";
                  }
              });
              return optionname.substring(0, optionname.length - 1);
          } else {
              return "";
          }
      },
      //初始化数据
      resetData() {
          this.tableData1 = [];
      },

      //查询条件校验
      queryCheck() {
          let msg;
          // this.instrId = this.instrId > 0 ? this.instrId : undefined;
          // msg = this.valid(this.instrId, "请选择仪器！"); //仪器校验
          // if (msg) return false;
          msg = this.valid(this.qcdate, "质控日期 必须填写！"); //时间校验
          if (msg) return false;
          msg = this.valid(this.qcdate[0], "开始日期 必须填写！"); //时间校验
          if (msg) return false;
          msg = this.valid(this.qcdate[1], "结束日期 必须填写！");
          if (msg) return false;
          return true;
      },
      infochange({ row }) {
          if (row.txtinfokind == "全部") {
              this.tableDataAdvice = this.tableDataAdviceall;
          } else {
              this.tableDataAdvice = this.tableDataAdviceall.filter((item) => item.txtinfokind == row.txtinfokind);
          }
      },
      AdviceClick({ row }) {
          if (this.advicetxt.indexOf(row.txtinfo) == -1) {
              if (this.appendChangeRow) {
                  this.advicetxt += "\n" + row.txtinfo;
              } else {
                  if (this.advicetxt) {
                      this.advicetxt += "," + row.txtinfo;
                  } else {
                      this.advicetxt += row.txtinfo;
                  }
              }
          }
      },
      AdvicedblClick({ row }) {
          this.advicetxt = row.txtinfo;
      },
      AdviceSubmit() {
          var type = "";
          switch (this.infortype) {
              case 0:
                  type = "outcontrolreason";
              // case 1:
              //     this.tempqcdata.outcontroloperation = this.advicetxt;
              //     break;
              // case 2:
              //     this.tempqcdata.outcontrolresult = this.advicetxt;
              //     break;
              // case 3:
              //     this.tempqcdata.cliniceffect = this.advicetxt;
              //     break;
              // case 4:
              //     this.tempqcdata.premunition = this.advicetxt;
              //     break;
              // case 5:
              //     if (this.tempappraise) this.tempappraise.appraisetext = this.advicetxt;
              //     else this.tempqcdata.comments = this.advicetxt;
              //     break;
              // case 6: 
              //     if (this.tempappraise) this.tempappraise.rechktext = this.advicetxt;
              //     else this.tempqcdata.comments = this.advicetxt;
              //     break;
              default:
                  break;
          }
          let updaterow = XEUtils.clone(this.currow, true);
          updaterow.outcontrolreason = this.advicetxt;
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS522",
                  method: "post",
                  data: {
                      action: "saveqcdata",
                      ...this.currow,
                      currow: this.currow,
                      updaterow: updaterow,
                      subtxt: this.advicetxt,
                      // oldqcdata: oldqcdata,
                      // reason: reason,
                      savetype: "out",
                  },
              })
              .then((res) => {
                  if (res.errcode == "1") {
                      this.$message({
                          message: "修改成功！",
                          type: "success",
                      });
                      this.currow.outcontrolreason = this.advicetxt;
                      this.dialogAdviceVisible = false;
                  } else {
                      this.$alert(res.errmsg, "错误");
                  }
              })
              .catch((error) => {
                  this.$alert(error, "错误");
              });
      },
      initialList() {
          //主表查询
          if (this.queryCheck() === false) return;
          this.currow = null;
          this.resetData();
          this.loading = true;
          var paramsJson = {
              qcdate1: this.qcdate[0], //质控日期
              qcdate2: this.qcdate[1],
              batchno: this.batchno, //批号
              qclevel: this.qclevel, //水平
              outcontrolok: this.outcontrolok,
              labgroupid: this.labgroupid, //所属工作组
              instrid: this.instrId, //质控仪器
              qcitem: this.qcitem == "All" ? "" : this.qcitem, //质控项目
          };
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS522",
                  method: "post",
                  data: {
                      action: "query",
                      ...paramsJson,
                  },
              })
              .then((response) => {
                  if (response.errcode == 1) {
                      this.tableData1 = response.Data;
                      this.loading = false;
                      if (response.printSql) this.printSql = response.printSql;
                  } else {
                      return this.$message({
                          message: "失控数据/失控报告查询异常",
                          type: "warning",
                      });
                  }
              })
              .catch((e) => {
                  this.loading = false;
              });
      },
      qclevelChange(code, name) {
          this.qclevel = code;
          this.qclevelname = name;
      },
      qcitemChange(code, name) {
          this.qcitem = code;
          this.qcitemname = name;
      },
      labgroupChange(code, name) {
          //检验工作组
          this.labgroupid = code;
          this.labgroupval = name;
      },

      //切换仪器时刷新界面
      labinstrumentchange(id, name) {
          this.instrId = Number(id);
          this.instrname = name;
          this.$nextTick(() => {
              this.initialList();
          });
      },
      //定义 失控单元格颜色
      getOutcontrolClassname({ row, rowIndex, $rowIndex, column }) {
          if (column.property == "controlstatus") {
              if (row.controlstatus == "0") return "setoutcontrolcolor";
              if (row.controlstatus == null) return "setoutcontrolcolorNull";
          }
          if (column.property == "outcontrolreason") return "dblcss";
      },
      ///////////////////////////////////工具函数 /////////////////////////////////////////
      //自制必填校验函数，以后待扩展
      valid(obj, message) {
          if (XEUtils.isUndefined(obj)) {
              return this.$message({
                  message: message,
                  type: "warning",
              });
          }
          if (XEUtils.isNull(obj)) {
              return this.$message({
                  message: message,
                  type: "warning",
              });
          }
          if (XEUtils.isString(obj)) {
              if (!XEUtils.getSize(obj) > 0) {
                  return this.$message({
                      message: message,
                      type: "warning",
                  });
              }
          }
          if (XEUtils.isDate(obj)) {
              if (obj < XEUtils.toStringDate("2000-01-01")) {
                  return this.$message({
                      message: message,
                      type: "warning",
                  });
              }
          }
      },
      ShowAdvice(row, infortype) {
          return new Promise((s, f) => {
              this.loadingAdvice = true;
              this.infortype = infortype;
              if (!row) this.tempappraise = "";
              this.$tool
                  .request({
                      url: "LIS/LIS5/LIS516",
                      method: "post",
                      data: {
                          action: "querytxtinfo",
                          instrid: this.instrId,
                          infotype: infortype,
                      },
                  })
                  .then((res) => {
                      if (res.data) {
                          this.tableDataAdviceall = res.data;
                          this.tableDataAdvice = res.data;
                          this.txtinfoarr = [{ txtinfokind: "全部" }];
                          for (let i = 0; i < res.kinds.length; i++) {
                              this.txtinfoarr.push(res.kinds[i]);
                          }

                          this.txtkind = "全部";
                          this.advicetxt = "";
                          this.dialogAdviceVisible = true;
                          this.$nextTick(() => {
                              this.$refs.txtinfokind.setCurrentRow(this.$refs.txtinfokind.getData(0));
                          });
                      }
                      if (infortype == 0) {
                          this.advicetxt = row.outcontrolreason;
                      }
                      this.loadingAdvice = false;
                  })
                  .catch((error) => {
                      this.loadingAdvice = false;
                      f(error);
                  });
          });
      },
      //预览
      previewData(StatColName, StatData) {
          let currentrow = this.$refs.xTable.getCurrentRow();
          if (currentrow) {
              this.bShowOutReport = true;
              this.rightloading = true;
              var tempolumns = this.$refs.xTable.getColumns();
              var pdfcolnalist = [];
              tempolumns.forEach((e) => {
                  var pdfcolna = {};
                  pdfcolna = { title: e.title, property: e.property };
                  pdfcolnalist.push(pdfcolna);
              });
              let str = JSON.stringify(pdfcolnalist);
              str += "\r";
              let tempdata = [];
              // tempdata.push(currentrow);
              // str += JSON.stringify(tempdata);
              this.$tool
                  .request({
                      url: "LIS/LIS5/LIS522",
                      method: "post",
                      data: {
                          action: "getqc_data_verify",
                          qcdataid: this.nowQcdataid,
                      },
                  })
                  .then((res) => {
                      let tempdata = [];
                      tempdata.push(currentrow);
                      str += JSON.stringify(tempdata);
                      this.verifyData = res.dt;
                      var data2 = this.verifyData;
                      var column2 = this.$refs.verifytable.getTableColumn().tableColumn;
                      if (data2 != null && data2.length > 0) {
                          str += "[RUIMEI]";
                          str += JSON.stringify(this.$pub.InitColumn(column2));
                          str += "\r";
                          str += JSON.stringify(data2);
                      }
                      this.signData = res.signdt;
                      var data3 = this.signData;
                      var column3 = this.$refs.signtable.getTableColumn().tableColumn;
                      if (data3 != null && data3.length > 0) {
                          str += "[RUIMEI]";
                          str += JSON.stringify(this.$pub.InitColumn(column3, "审核人签名,checkusersign,byte|处理人签名,outcontrolusersign,byte"));
                          str += "\r";
                          str += JSON.stringify(data3);
                      }
                      this.$tool
                          .request({
                              url: "ucent/print",
                              method: "post",
                              data: {
                                  action: "previewpdf",
                                  styleid: "5092",
                                  sql: str,
                                  tablename: "质控失控记录表",
                              },
                          })
                          .then((res) => {
                              if (res.flag == "0") {
                                  this.$alert(res.msg, "提示");
                              } else {
                                  this.htmlstr = res.pdfurl + "#toolbar=0";
                                  //var url = res.pdfurl;
                                  // console.log("url", url);
                                  // this.prePDFDialogShow(url);
                                  this.htmlstrkey++;
                              }
                              this.rightloading = false;
                          })
                          .catch((e) => {
                              this.$alert("预览报告出错！", "错误", {
                                  confirmButtonText: "确定",
                              });
                              this.rightloading = false;
                          });
                      // let sql = btoa(encodeURIComponent(str));
                      // jsObj.PrintCustomJsonReport("5092", sql, "admin", "质控失控记录表", "");
                  })
                  .catch((e) => {
                      console.log(e);
                  });
              // let sql = btoa(encodeURIComponent(str));
          } else {
              this.$message.info("请先选择一条失控数据。");
          }
      },
      printrecord(flag) {
          let printdata = this.$refs.xTable.afterFullData;
          if (printdata.length == 0) {
              this.$message.info("没有要打印的数据！");
          } else {
              let column = this.$refs.xTable.getTableColumn().tableColumn;

              let str = JSON.stringify(this.$pub.InitColumn(column));
              str += "\r";
              if (flag == 1) {
                  str += JSON.stringify(printdata);
                  let sql = btoa(encodeURIComponent(str));
                  jsObj.PrintCustomJsonReport("5091", sql, "admin", "失控清单样式", "");
              } else {
                  let currentrow = this.$refs.xTable.getCurrentRow();
                  if (currentrow) {
                      this.$tool
                          .request({
                              url: "LIS/LIS5/LIS522",
                              method: "post",
                              data: {
                                  action: "getqc_data_verify",
                                  qcdataid: this.nowQcdataid,
                              },
                          })
                          .then((res) => {
                              let tempdata = [];
                              tempdata.push(currentrow);
                              str += JSON.stringify(tempdata);
                              this.verifyData = res.dt;
                              var data2 = this.verifyData;
                              var column2 = this.$refs.verifytable.getTableColumn().tableColumn;
                              if (data2 != null && data2.length > 0) {
                                  str += "[RUIMEI]";
                                  str += JSON.stringify(this.$pub.InitColumn(column2));
                                  str += "\r";
                                  str += JSON.stringify(data2);
                              }
                              // this.signData = res.signdt;
                              // var data3 = this.signData;
                              // var column3 = this.$refs.signtable.getTableColumn().tableColumn;
                              // if (data3 != null && data3.length > 0) {
                              //     str += "[RUIMEI]";
                              //     str += JSON.stringify(this.$pub.InitColumn(column3));
                              //     str += "\r";
                              //     str += JSON.stringify(data3);
                              // }
                              this.signData = res.signdt;
                              var data3 = this.signData;
                              var column3 = this.$refs.signtable.getTableColumn().tableColumn;
                              if (data3 != null && data3.length > 0) {
                                  str += "[RUIMEI]";
                                  str += JSON.stringify(this.$pub.InitColumn(column3, "审核人签名,checkusersign,byte|处理人签名,outcontrolusersign,byte"));
                                  str += "\r";
                                  str += JSON.stringify(data3);
                              }
                              let sql = btoa(encodeURIComponent(str));
                              jsObj.PrintCustomJsonReport("5092", sql, "admin", "质控失控记录表", "");
                          })
                          .catch((e) => {
                              console.log(e);
                          });
                  } else {
                      this.$message.info("请先选择一条失控数据。");
                  }
              }
          }
      },
      getqc_data_verify() {},
      RptStyleSetting(flag) {
          var user = this.$tool.getSession(this.$tool.loginuserno);
          if (user != "admin") {
              this.$message.error("如需调整样式请联系管理员。");
          } else {
              this.$tool
                  .request({
                      url: "LIS/LIS5/LIS522",
                      method: "post",
                      data: {
                          action: "getqc_data_verify",
                          qcdataid: this.nowQcdataid,
                      },
                  })
                  .then((res) => {
                      this.verifyData = res.dt;
                      var data2 = this.verifyData;
                      var column2 = this.$refs.verifytable.getTableColumn().tableColumn;
                      // this.signData = res.signdt;
                      // var data3 = this.signData;
                      // var column3 = this.$refs.signtable.getTableColumn().tableColumn;
                      if (flag == 1) {
                          var data = this.$refs.xTable.tableData;
                          if (data.length > 0) {
                              const rload = this.$pub.openLoading(this, "正在打开报表设计器，请稍候……");
                              let column = this.$refs.xTable.getTableColumn().tableColumn;
                              let str = JSON.stringify(this.$pub.InitColumn(column));
                              str += "\r";
                              str += JSON.stringify(data);
                              if (data2 != null && data2.length > 0) {
                                  str += "[RUIMEI]";
                                  str += JSON.stringify(this.$pub.InitColumn(column2));
                                  str += "\r";
                                  str += JSON.stringify(data2);
                              }
                              // if (data3 != null && data3.length > 0) {
                              //     str += "[RUIMEI]";
                              //     str += JSON.stringify(this.$pub.InitColumn(column3));
                              //     str += "\r";
                              //     str += JSON.stringify(data3);
                              // }
                              let sql = btoa(encodeURIComponent(str));
                              jsObj.SetCustomJsonPrintConfig("5091", sql, "admin", "失控清单样式");
                              rload.close();
                          } else {
                              this.$message.info("没有要打印的数据！");
                          }
                      } else {
                          let currentrow = this.$refs.xTable.getCurrentRow();
                          if (currentrow) {
                              const rload = this.$pub.openLoading(this, "正在打开报表设计器，请稍候……");
                              let column = this.$refs.xTable.getTableColumn().tableColumn;
                              let str = JSON.stringify(this.$pub.InitColumn(column));
                              str += "\r";
                              let tempdata = [];
                              tempdata.push(currentrow);
                              str += JSON.stringify(tempdata);
                              if (data2 != null && data2.length > 0) {
                                  str += "[RUIMEI]";
                                  str += JSON.stringify(this.$pub.InitColumn(column2));
                                  str += "\r";
                                  str += JSON.stringify(data2);
                              }
                              this.signData = res.signdt;
                              var data3 = this.signData;
                              var column3 = this.$refs.signtable.getTableColumn().tableColumn;
                              if (data3 != null && data3.length > 0) {
                                  str += "[RUIMEI]";
                                  str += JSON.stringify(this.$pub.InitColumn(column3, "审核人签名,checkusersign,byte|处理人签名,outcontrolusersign,byte"));
                                  str += "\r";
                                  str += JSON.stringify(data3);
                              }
                              // if (data3 != null && data3.length > 0) {
                              //     str += "[RUIMEI]";
                              //     str += JSON.stringify(this.$pub.InitColumn(column3));
                              //     str += "\r";
                              //     str += JSON.stringify(data3);
                              // }
                              let sql = btoa(encodeURIComponent(str));
                              jsObj.SetCustomJsonPrintConfig("5092", sql, "admin", "质控失控记录表");
                              rload.close();
                          } else {
                              this.$message.info("请先选择一条失控数据。");
                          }
                      }
                  })
                  .catch((e) => {
                      console.log(e);
                  });
          }
      },
      printOutControlRpt() {
          let currentrow = this.$refs.xTable.getCurrentRow();
          if (currentrow) {
              let column = this.$refs.xTable.getTableColumn().tableColumn;
              let str = JSON.stringify(this.$pub.InitColumn(column));
              str += "\r";
              str += JSON.stringify(currentrow);
              let sql = btoa(encodeURIComponent(str));
              jsObj.PrintCustomJsonReport("5092", sql, "admin", "质控月统计报表", "");
          }
      },
      btnPrint(type) {
          var that = this;
          if (type == 1 && that.printSql) {
              if (that.styleIdQCList) {
                  that.$pub.printlistbill(that, that.printSql, "3", that.styleIdQCList, "质控清单", "");
              } else {
                  return this.$message({
                      message: "未获取到打印样式id，请刷新页面后重试",
                      type: "warning",
                  });
              }
          }
          if (type == 2) {
              // console.log("nowQcdataid:" + that.nowQcdataid);
              var paramsJson = {
                  qcdate1: that.qcdate[0], //质控日期
                  qcdate2: that.qcdate[1],
                  batchno: that.batchno, //批号
                  qclevel: that.qclevel, //水平
                  outcontrolok: that.outcontrolok,
                  labgroupid: that.labgroupid, //所属工作组
                  instrid: that.instrId, //质控仪器
                  qcitem: that.qcitem == "All" ? "" : that.qcitem, //质控项目
                  qcdataid: that.nowQcdataid, //当前一条记录 质控结果ID
              };
              that.$tool
                  .request({
                      url: "LIS/LIS5/LIS522",
                      method: "post",
                      data: {
                          action: "query",
                          ...paramsJson,
                      },
                  })
                  .then((response) => {
                      if (response.errcode == 1) {
                          if (response.printSql) {
                              if (that.styleIdQCList) {
                                  that.$pub.printlistbill(that, response.printSql, "3", that.styleIdOC, "失控报告", "");
                              } else {
                                  return that.$message({
                                      message: "未获取到打印样式id，请刷新页面后重试",
                                      type: "warning",
                                  });
                              }
                          }
                      }
                      //  else {
                      //     return that.$message({
                      //         message: "失控数据/失控报告查询异常",
                      //         type: "warning"
                      //     });
                      // }
                  });
          }
      },
      currentChangeEvent({ row, rowIndex }) {
          // console.log(row.qcdataid);
          this.nowQcdataid = row.qcdataid;
      },
      //关闭按钮
      BtnExc() {
          let index = this.$parent.$refs.itemtags.tagsList.findIndex((m) => m.name == "LIS522");
          this.$parent.$refs.itemtags.tagsList.splice(index, 1);
          this.$router.go(-1);
      },
  },
  beforeRouteEnter(to, from, next) {
      next((vm) => {
          let that = vm;
          let altArr = [];
          document.onkeydown = function (e) {
              let key = window.event.keyCode;
              //*组合按键
              if (altArr.length > 0) {
                  //65到90 a到z（A到Z）
                  // //*Alt + C 清除
                  // if (key == 67) {
                  //     this.BtnExc();
                  // }
                  if (key == 88) {
                      //*Alt + X 退出
                      that.BtnExc();
                  }
              } else {
                  if (key == 119) {
                      //F8
                      that.initialList();
                  } else if (key == 121) {
                      //F10
                      that.btnPrint(1);
                  } else if (key == 122) {
                      //F11
                      that.btnPrint(2);
                  } else if (key == 18) {
                      //按下了alt
                      altArr.push(key);
                  }
              }
          };
          document.onkeyup = function (e) {
              let key = window.event.keyCode;
              if (key == 18) {
                  altArr = [];
              }
          };
      });
  },
};
</script>

<style scoped>
.pagetop {
  left: 0;
  right: 0;
  height: 90px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: solid 1px #ccc;
  position: absolute;
  z-index: 99;
  text-align: left;
  overflow-x: auto;
}
.pagebottom {
  width: 100%;
  height: 40px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: left;
  position: absolute;
  bottom: 0px;
  font-size: 12px;
  border: solid 1px #ccc;
}
.pagecenter {
  position: absolute;
  top: 95px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}
.middle-center {
  position: absolute;
  height: 100%;
  right: 485px;
  left: 0;
}

.middle-right {
  position: absolute;
  top: 0;
  bottom: 2px;
  overflow: visible;
  width: 480px;
  right: 0px;
}

table tr td:nth-child(1) {
  width: 80px;
}
table {
  font-size: 12px;
}
::v-deep .setoutcontrolcolor {
  background-color: #ff6666 !important;
}
::v-deep .setoutcontrolcolorNull {
  background-color: #cccccc !important;
}
::v-deep .mytable-style.vxe-table .vxe-body--column.dblcss {
  background-color: #e6d7f7;
  cursor: pointer;
}
</style>
// table tr td:nth-child(odd) {
//     text-align: right;
//     white-space: nowrap;
// }
// table tr td:nth-child(even) {
//     text-align: left;
// }